﻿using SpaceNeedle.SDK.Windows.Platform.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SpaceNeedle.x6473.WindowsPhone.Common
{
    public class WebRequestBase
    {
        protected string GetQuerystring(params string[] args)
        {
            string data = string.Empty;

            try
            {
                if (args != null && args.Length > 1)
                {
                    data = "?";

                    for (int i = 0; i < args.Length; i++)
                    {
                        if (i > 0)
                        {
                            data += "&";
                        }

                        data += args[i] + "=" + args[++i];
                    }
                }
            }
            catch { }

            return data;
        }

        protected string GetJsonContent(params string[] args)
        {
            string data = string.Empty;

            try
            {
                if (args != null && args.Length > 1)
                {
                    data = "{";

                    for (int i = 0; i < args.Length; i++)
                    {
                        data += @"""" + args[i] + @"""" + ":" + @"""" + args[++i] + @""",";
                    }

                    data += "}";

                    data = data.Replace(",}", "}");
                }
            }
            catch { }

            return data;
        }

        public virtual Task<string> DownloadStringAsync(string uri, string method, params string[] args)
        {
            throw new NotImplementedException();
        }

        public virtual Task<HttpResponse<T>> DownloadStringAsync<T>(string uri, string method, Dictionary<string, string> headers, params string[] args)
        {
            throw new NotImplementedException();
        }

        public virtual Task<HttpResponse<T>> DownloadApiStringAsync<T>(string uri, string method, Dictionary<string, string> headers, string httpContent, params string[] args)
        {
            throw new NotImplementedException();
        }
    }
}
